from time import sleep
from Page.basepage import BasePage
element1 = "登录/注册"


class Login(BasePage):
    def oneclicklogin(self):  # 一键登录操作

        if self.findItem(element1) is True:
            self.steps('/TestData/login.yaml', 'oneclicklogin', )
        else:
            self.logout()
            self._driver.close_app()
            self._driver.launch_app()
            self.steps('/TestData/main.yaml', 'go_my_login', 'com.zxkt.eduol:id/login_lne')
            return self.oneclicklogin()

    def loginByPassword(self, account, password):  # 账号密码登录
        # if self.element_count() <= 1:
        if self.findItem(element1) is True:
            self.steps('/TestData/login.yaml', 'loginByPassword', var1=account, var2=password)
        else:
            self.logout()
            self.steps('/TestData/login.yaml', 'loginByPassword', var1=account, var2=password)
        # else:
        #     if self.findItem(element1) is True:
        #         self.steps('/TestData/login.yaml', 'loginByPassword2', var1=account, var2=password)
        #     else:
        #         self.logout()
        #         self.steps('/TestData/login.yaml', 'loginByPassword2', var1=account, var2=password)

    def login_go(self):
        self.steps('/TestData/login.yaml', 'logingo')

    def login_back(self):
        self.steps('/TestData/login.yaml', 'loginback')

    def logout(self):  # 退出登录操作
        self.steps('/TestData/login.yaml', 'logout')
        # sleep(1)

    def back(self):  # 返回操作
        self.steps('/TestData/login.yaml', 'back')
